home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / animate_next / Controller.m < prev    next >
Text File  |  1993-11-04  |  5KB  |  254 lines

  1.  
  2. #import "Controller.h"
  3.  
  4. #include <stdio.h>
  5.  
  6. @implementation Controller
  7.  
  8. void runOneStep(DPSTimedEntry timedEntry, double timeNow, void *data)
  9. {
  10.     [(id)data step];
  11. }
  12.  
  13. // for future reference:
  14. // asyn_getc() returns char code, EOF or NONE(-2) defined in <geomutil.h>
  15.  
  16. - displayFrame:(int)frameno
  17. {
  18.     int num;
  19.     
  20.     fprintf(stdout,"(progn");
  21.     fprintf(stdout,"(geometry animate : a%d)\n", frameno);
  22.     fprintf(stdout,"(echo \"1\n\"))\n");
  23.     fflush(stdout);
  24.     fscanf(stdin,"%d",&num);
  25.     if(hiliteFrame) {
  26.         [theMatrix selectCellAt:frameno :0];
  27.     [theMatrix scrollCellToVisible:frameno :0];
  28.     }
  29.     if(commandFlag) fprintf(stdout,"%s",commandString);
  30.     return self;
  31. }
  32.  
  33. - appDidInit:sender
  34. {
  35.     [animateWindow setAvoidsActivation:YES];
  36.     fps = [fpsField intValue];
  37.     timerEnabled = NO;
  38.     theMode = forward;
  39.     bounceDir = 1;
  40.     [browser setDelegate:self];
  41.     theMatrix = [browser matrixInColumn:0];
  42.     hiliteFrame = NO;
  43.     onceFlag = NO;
  44.     return self;
  45. }
  46.  
  47. - (int)browser:sender fillMatrix:theMatrix inColumn:(int)column
  48. {
  49.     NXBrowserCell *theCell;
  50.     int i=0;
  51.     
  52.     while (filesbase && *filesbase) {
  53.     [theMatrix addRow];
  54.     theCell = [theMatrix cellAt:i :0];
  55.     [theCell setStringValue:(char *)*filesbase];
  56.     [[theCell setLoaded:YES] setLeaf:YES];
  57.     filesbase++;
  58.     i++;
  59.     }
  60.  
  61.     return i;
  62. }
  63.  
  64. - browserCellSelected:sender
  65. {
  66.     int n = [theMatrix selectedRow];
  67.     if(timerEnabled) {
  68.         DPSRemoveTimedEntry(timer);
  69.     timerEnabled = NO;
  70.     }
  71.     [self displayFrame:n];
  72.     return self;
  73. }
  74.  
  75. - hiliteCurrentFrame:sender
  76. {
  77.     hiliteFrame = [sender intValue];
  78.     return self;
  79. }
  80.  
  81. - step
  82. {
  83.     switch(theMode) {
  84.     
  85.     case forward:
  86.     currentFrame++;
  87.     if(currentFrame>=frames) {
  88.         if(onceFlag) {
  89.             onceFlag = NO;
  90.         DPSRemoveTimedEntry(timer);
  91.         timerEnabled = NO;
  92.         currentFrame = frames - 1;
  93.         }
  94.     else currentFrame = 0;
  95.     }
  96.     break;
  97.     
  98.     case reverse:
  99.     currentFrame--;
  100.     if(currentFrame<0) currentFrame = frames - 1;
  101.     break;
  102.     
  103.     case bounce:
  104.     currentFrame += bounceDir;
  105.     if(currentFrame>=frames) {
  106.         bounceDir *= -1;
  107.         if(frames>1) currentFrame += 2*bounceDir;
  108.         else currentFrame = 0;
  109.     }
  110.     if(currentFrame<0) {
  111.         bounceDir *= -1;
  112.         if(frames>1) currentFrame += 2*bounceDir;
  113.         else currentFrame = 0;
  114.         }
  115.     break;
  116.     }
  117.     
  118.     [self displayFrame:currentFrame];
  119.     
  120.     return self;
  121. }
  122.  
  123. - bounce:sender
  124. {
  125.     if(!timerEnabled) {
  126.         timer = DPSAddTimedEntry(1./fps, &runOneStep, self, NX_BASETHRESHOLD);
  127.     timerEnabled = YES;
  128.     }
  129.     theMode = bounce;
  130.     return self;
  131. }
  132.  
  133. - command:sender
  134. {
  135.     [[commandField window] makeKeyAndOrderFront:self];
  136.     return self;
  137. }
  138.  
  139. - commandEntered:sender
  140. {
  141.     strcpy(commandString,[sender stringValue]);
  142.     commandFlag = YES;
  143.     return self;
  144. }
  145.  
  146. - readSingleFile:(char *)filename
  147. {
  148.     fprintf(stdout,"(hdefine \"geometry\" a%d < \"%s\")\n", currentFrame, filename);
  149.     fflush(stdout);
  150.     return self;
  151. }
  152.  
  153. - load:sender
  154. {
  155.     char fullname[512];
  156.     id openpanel = [OpenPanel new];
  157.     NXBrowserCell *theCell;
  158.     
  159.     [NXApp activateSelf:YES];  
  160.     [openpanel allowMultipleFiles:YES];
  161.     //[openpanel setAccessoryView:[accessoryPanel contentView]];
  162.     
  163.     
  164.     if ([openpanel runModal]) {
  165.     files = filesbase = [openpanel filenames];
  166.     directory = [openpanel directory];
  167.     
  168.     frames = 0;
  169.     currentFrame = 0;
  170.     while (files && *files) {
  171.         //[theMatrix addRow];
  172.         //theCell = [theMatrix cellAt:currentFrame :0];
  173.         //[theCell setStringValue:(char *)*files];
  174.         //[[theCell setLoaded:YES] setLeaf:YES];
  175.         //[theMatrix display];
  176.         //[browser displayColumn:0];
  177.         sprintf(fullname,"%s/%s",directory, (char *)*files);
  178.         fprintf(stdout,"(hdefine \"geometry\" a%d < \"%s\")\n",
  179.             currentFrame, fullname);
  180.          [self displayFrame:currentFrame];
  181.         files++;
  182.         currentFrame++;
  183.         frames++;
  184.     }
  185.     if(frames) [self displayFrame:0];
  186.     [browser loadColumnZero];
  187.     }
  188.     
  189.     [NXApp deactivateSelf];
  190.     return self;
  191. }
  192.  
  193. - loop:sender
  194. {
  195.     if(!timerEnabled) {
  196.         timer = DPSAddTimedEntry(1./fps, &runOneStep, self, NX_BASETHRESHOLD);
  197.     timerEnabled = YES;
  198.     }
  199.     return self;
  200. }
  201.  
  202. - once:sender
  203. {
  204.     onceFlag = YES;
  205.     theMode = forward;
  206.     if(!timerEnabled) {
  207.     currentFrame = -1;
  208.         timer = DPSAddTimedEntry(1./fps, &runOneStep, self, NX_BASETHRESHOLD);
  209.     timerEnabled = YES;
  210.     }
  211.     return self;
  212. }
  213.  
  214. - stepdown:sender
  215. {
  216.     currentFrame--;
  217.     if(currentFrame<0) currentFrame = frames-1;
  218.     if(frames) [self displayFrame:currentFrame];
  219.     theMode = reverse;
  220.     bounceDir = -1;
  221.     if(timerEnabled) {
  222.         timerEnabled = NO;
  223.     DPSRemoveTimedEntry(timer);
  224.     }
  225.     return self;
  226. }
  227.  
  228. - stepup:sender
  229. {
  230.     currentFrame++;
  231.     if(currentFrame>=frames) currentFrame = 0.0;
  232.     if(frames) [self displayFrame:currentFrame];
  233.     theMode = forward;
  234.     bounceDir = 1;
  235.     if(timerEnabled) {
  236.         timerEnabled = NO;
  237.     DPSRemoveTimedEntry(timer);
  238.     }
  239.     return self;
  240. }
  241.  
  242. - fpsEntered:sender
  243. {
  244.     fps = [fpsField intValue];
  245.     if(timerEnabled) {
  246.         DPSRemoveTimedEntry(timer);
  247.     NXPing(); // Not sure we need this
  248.     DPSAddTimedEntry(1./fps, &runOneStep, self, NX_BASETHRESHOLD);
  249.     }
  250.     return self;
  251. }
  252.  
  253. @end
  254.